package com.dingding.web.validate;

import com.dingding.common.core.util.ToolUtil;
import com.dingding.facade.mall.status.StatusCode;
import com.dingding.web.base.action.BaseAction;

/**
 * 
 * @ClassName: CodeAction 
 * @Description: 图形验证码校验
 * @author hufan
 * @date 2016年12月6日 下午2:00:17 
 *
 */
public class CodeAction extends BaseAction {

	private static final long serialVersionUID = -1052893082491607965L;

	private String code;//
	
	/**
	 * @Title: validateCodeIsValid 
	 * @Description:异步验证验证码是否正确
	 * @return String    返回类型 
	 * @throws
	 */
	public String validateCodeIsValid() {
		//先校验验证码是否正确
		String str = (String) request.getSession().getAttribute(request.getSession().getId());
		if(ToolUtil.isBlank(code)) {
			super.writeResponseJsonp(StatusCode.RESULT_NULL_ERROR, StatusCode.RESULT_NULL_ERROR_MESSAGE);
			return NONE;
		}
		if(ToolUtil.isBlank(str) || !str.toUpperCase().equals(code.toUpperCase())){
			super.writeResponseJsonp(StatusCode.RESULT_NULL_ERROR, StatusCode.RESULT_NULL_ERROR_MESSAGE);
			return NONE;
		}else {
			super.writeResponseJsonp(StatusCode.SUCCESS, StatusCode.SUCCESS_MESSAGE);
			return NONE;
		}
		
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}
	
	
}
